package com.xh.cdp.sys.service.impl;

import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xh.cdp.common.EasyUIPageModel;
import com.xh.cdp.sys.dao.SysMenuDao;
import com.xh.cdp.sys.dao.SysRoleDao;
import com.xh.cdp.sys.dao.SysRoleMenuDao;
import com.xh.cdp.sys.entity.SysRoleEntity;
import com.xh.cdp.sys.service.SysRoleService;

@Service
public class SysRoleServiceImpl implements SysRoleService {

	@Autowired
	private SysRoleDao sysRoleDao;
	@Autowired
	private SysMenuDao sysMenuDao;
	@Autowired
	private SysRoleMenuDao sysRoleMenuDao;

	@Override
	public List<SysRoleEntity> listUserRoleCombobox(String cate) {
		return sysRoleDao.listUserRoleCombobox(cate);
	}

	@Override
	public EasyUIPageModel<SysRoleEntity> listRole(String sort, String order,
			int page, int rows) {
		return sysRoleDao.listRole(sort, order, page, rows);
	}

	@Override
	public String addRole(SysRoleEntity role, String rolePower) {
		String roleId = sysRoleDao.addRole(role);
		Set<String> fatherMenuIds = sysMenuDao.getFatherMenuIds(rolePower);
		sysRoleMenuDao.addRoleMenu(rolePower, fatherMenuIds, roleId);
		return roleId;
	}

	@Override
	public String updateRole(SysRoleEntity role, String rolePower) {
		sysRoleMenuDao.deleteRoleMenuInPhysical(role);
		Set<String> fatherMenuIds = sysMenuDao.getFatherMenuIds(rolePower);
		sysRoleMenuDao.addRoleMenu(rolePower, fatherMenuIds, role.getId());
		return sysRoleDao.updateRole(role);
	}

	@Override
	public SysRoleEntity showRoleInfo(String id) {
		return sysRoleDao.showRoleInfo(id);
	}

	@Override
	public Integer updateRoleState(SysRoleEntity role) {
		return sysRoleDao.updateRoleState(role);
	}

	@Override
	public Integer deleteRole(String ids) {
		return sysRoleDao.deleteRole(ids);
	}

	@Override
	public EasyUIPageModel<SysRoleEntity> listRoleBySearch(String sort,
			String order, Integer page, Integer rows, String searchName,
			Integer state) {
		return sysRoleDao.listRoleBySearch(sort, order, page, rows, searchName,
				state);
	}

}
